package com.acyouzi.leetcode.array;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

/**
 * 17/9/17 22:10
 *
 * @author sunxu
 */
public class BrickWall {
  public int leastBricks(List<List<Integer>> wall) {
    HashMap<Integer, Integer> map = new HashMap<>();
    for (List<Integer> list : wall){
      int sum = 0;
      Iterator<Integer> it = list.iterator();
      while (it.hasNext()){
        sum += it.next();
        map.put(sum,map.getOrDefault(sum,0)+1);
      }
      map.remove(sum);
    }
    int max = 0;
    for (int i : map.values()) max = Math.max(max,i);
    return wall.size() - max;
  }
}
